<template>
	<view>
		<view class="nav-back">
			<top-heigth :backTitle="backTitle"></top-heigth>
		</view>	
		
		
		<view class="kong-box" v-if="list.length < 0 || list.length == null">
			<uv-empty mode="" text="没有可领取的优惠，敬请期待~" icon="/static/image/kong-quan.png"></uv-empty>
		</view>
		
		<view class="content-box" v-if="list.length > 0">
			<view class="public-box m-b16 m-t24">
				
				<view class="coupon-box" v-for="(item,index) in list">
					<view class="coupon-top">
						<view class="coupon-l-box">
							<view class="coupon-l">
								 <view class="coupon-l-red">
								 	<span>¥</span>{{item.couponAmount}}
								 </view>
								<view class="coupon-l-black">满{{item.couponLimitAmount}}可用</view>
							</view>
							<view class="coupon-c">
								<view><b>{{item.couponName}}</b></view><!-- item.beginTime.substring(0,6) -->
								<view v-if="item.beginTime!=null" class="font-hui m-t16">
								{{(item.beginTime).substring(0,10)}}-{{(item.endTime).substring(0,10)}}
								</view>
							</view>
						</view>
						<view class="coupon-but-red" v-if="!item.hasTake" @click="toTackCoupon(item.id)">立即领取</view>
						<view class="coupon-but-hui" v-else>已领取</view>
					</view>
					<view class="coupon-bottom">
						<view class="font-hui">全场通用</view>
						<view v-if="item.couponType == 1" class="font-hui">新用户可领</view>
						<view v-if="item.couponType == 2" class="font-hui">老用户可领</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import TopHeigth from '@/components/TopHeigth.vue'
	import { checkLogin } from "@/util/checkLogin.js"
	
	export default {
		data() {
			return {
				backTitle:"领券专区",
				list:'',
			}
		},
		components: { TopHeigth },
		onLoad() {
			this.listTui()
		},
		methods: {
			listTui(){
				uni.$u.http.post('/api/shop/v1_0/tAppCouponRCA/queryTAppCoupon',{
					isOn:1,
				}).then((res) => {
					this.list = res.aaData
				}) 
			},
			goback(){
				uni.navigateBack()
			},
			toTackCoupon(id){
				
				checkLogin(() => {
					uni.$u.http.post('/api/shop/v1_0/tAppCouponUserRCA/insertTAppCouponUser',{
						couponId: id
					}).then((res) => {
						uni.showToast({
							icon: "none",
							title: res.message
						})
						if(res.code == 200){
							this.listTui()
						}						
					}) 
				})
				
			},
		}
	}
</script>

<style lang="scss" scoped>
	@mixin flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: $direction;
	}
	.uv-nav-slot {
		@include flex;
		align-items: center;
		justify-content: space-between;
		border-width: 0.5px;
		border-radius: 100px;
		border-color: #dadbde;
		padding: 3px 7px;
		opacity: 0.8;
	}
	
	.coupon-box{
		height: 236rpx;
		border-radius: 26rpx;
		border: 3rpx solid #f9c9b4;
		background:#fff3f0 url("/static/image/coupon.png") right no-repeat;
		background-size: auto 236rpx;
		padding: 0 20rpx;
		margin-bottom: 20rpx;
	}
	.coupon-top{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 0;
	}
	.coupon-bottom{
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-top: 2rpx dashed #D8D8D8;
	}
	.coupon-l{
		padding-right: 24rpx;
	}
	.coupon-c{
		padding-left: 24rpx;
		border-left: 2rpx solid #D8D8D8;
	}
	.coupon-l-red{
		font-size: 56rpx;
		color: #FF0202;
		font-weight: bold;
		span{
			font-size: 34rpx;
		}
	}
	.coupon-but-red{
		height: 56rpx;
		border-radius: 56rpx;
		padding: 0 18rpx;
		text-align: center;
		line-height:56rpx;
		color: #fff;
		font-size: 24rpx;
		background-color: #F51212;
	}
	.coupon-but-hui{
		height: 56rpx;
		border-radius: 56rpx;
		padding: 0 18rpx;
		text-align: center;
		line-height:56rpx;
		color: #fff;
		font-size: 24rpx;
		background-color: #ccc;
	}
	.coupon-l-box{
		display: flex;
		align-items: center;
		justify-content: flex-start;
	}
	.coupon-l-black{
		font-size: 24rpx;
		color: #333;
	}
	.coupon-c{
		font-size: 30rpx;
		color: #333;
	}
	.coupon-bottom{
		padding: 20rpx 0;
	}
</style>
